import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login/login.vue'),
    },
    {
      path: '/login1',
      name: 'login1',
      component: () => import('../views/login/login1.vue'),
    },
    {
      path: '/login2',
      name: 'login2',
      component: () => import('../views/login/login2.vue'),
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('../views/login/register.vue'),
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('../views/home/home.vue'),
    },
  ],
})
import { ElMessage } from 'element-plus'
let sho=['/register','/login','/login1','/login2']
router.beforeEach((to, from, next) => {
  let accessToken=localStorage.getItem('accessToken')
  if(!accessToken){
    if(sho.includes(to.path)){
      next()
    }else{
      next('/login')
      ElMessage.error('Oops, this is a error message.')
    }
  }else{
    next()
  }
})
export default router
